package com.example.sj12;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.signature.StringSignature;
import com.example.sj12.ui.dashboard.DashboardFragment;

import java.util.LinkedList;

public class DataAdapterComment extends BaseAdapter {
    private LinkedList<Data> mData;//定义存储具体元素的链表
    private Context mContext;//设备上下文对象
    //初始化成员对象
    public DataAdapterComment(LinkedList<Data> mData, Context mContext) {
        this.mData = mData;
        this.mContext = mContext;
    }
    @Override
    public int getCount() {
        return mData.size();//返回元素的实际大小
    }
    @Override
    public Object getItem(int position) {
        return position;
    }
    @Override
    public long getItemId(int position) {
        return position;//返回具体项
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        //视图对象通过Inflater找到视图对象
        //convertView = LayoutInflater.from(mContext).inflate(R.layout.activity_commentlv,parent,false);//mContext.getContext()
        convertView = LayoutInflater.from(mContext).inflate(R.layout.activity_commentlv,parent,false);
        //定义控件对象并与控件进行绑定
        ImageView img_icon = (ImageView) convertView.findViewById(R.id.image);
        TextView txt_aName = (TextView) convertView.findViewById(R.id.tv1);
        TextView txt_aSpeak = (TextView) convertView.findViewById(R.id.tv2);
        TextView time = (TextView) convertView.findViewById(R.id.tv3);
        RatingBar rating=convertView.findViewById(R.id.rb);
        //修改控件内容
        Glide.with(parent.getContext()).load(mData.get(position).getUrl()).diskCacheStrategy(DiskCacheStrategy.NONE)//磁盘不缓存
                .skipMemoryCache(true).into(img_icon);
        //img_icon.setBackgroundResource(mData.get(position).getaIcon());
        txt_aName.setText(mData.get(position).getUsername());
        txt_aSpeak.setText(mData.get(position).getComment());
        time.setText(mData.get(position).getTimeinto());
        time.setTextColor(0x66ff00ff);//设置字体颜色
        rating.setRating(mData.get(position).getRating());
        return convertView;//返回视图对象
    }
}